package com.foreknow.dao.impl;

import com.foreknow.dao.IBaseDao;
import com.foreknow.entity.User;
import com.foreknow.util.DbHelper;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.ResultSetHandler;
import org.apache.commons.dbutils.handlers.BeanHandler;
import org.apache.commons.dbutils.handlers.BeanListHandler;

import java.sql.SQLException;
import java.util.List;

public class UserDaoImpl implements IBaseDao<User> {
    private static QueryRunner qr = DbHelper.getQueryRunner();

    @Override
    public int delete(String sql, Object... params) throws SQLException {
        return qr.update(sql,params);
    }

    @Override
    public int delete(String sql) throws SQLException {
        return qr.update(sql);
    }

    @Override
    public int insert(String sql, Object[] params) throws SQLException {
        return qr.update(sql,params);
    }

    @Override
    public List queryByCondition(String sql) throws SQLException {
        return qr.query(sql,new BeanListHandler<>(User.class));
    }

    @Override
    public List queryByCondition(String sql, Object... params) throws SQLException {
        return qr.query(sql,new BeanListHandler<>(User.class),params);
    }

    @Override
    public User queryOne(String sql, Object param) throws SQLException {
        return qr.query(sql,new BeanHandler<>(User.class),param);
    }

    @Override
    public int update(String sql, Object... params) throws SQLException {
        return qr.update(sql,params);
    }

    @Override
    public int update(String sql, Object param) throws SQLException {
        return qr.update(sql,param);
    }

    @Override
    public ResultSetHandler getResultSetHandler() {
        return null;
    }
}
